package top.saplf.sileny.ext

import java.io.File
import java.io.FileInputStream
import java.io.FileOutputStream

/**
 * @author Saplf on 17/4/12
 */
fun File.ensureExist(): File {
    if (!exists()) {
        mkdirs()
    }
    return this
}

fun File.copyTo(toFile: File) {
    FileInputStream(this).channel.use { input ->
        FileOutputStream(toFile).channel.use { output ->
            output.transferFrom(input, 0, input.size())
        }
    }
}

fun File.copyTo(toFile: String) {
    copyTo(File(toFile))
}

fun String.copyTo(toFile: String) {
    File(this).copyTo(toFile)
}
